from RestAPI.amazon.service import AWSrequest
from RestAPI.amazon.service import AWSservice
##
#Basic request of Product API
class ProductAPIrequest(AWSrequest):
    POSSIBLE_OPERATION=()
    def __init__(self,locale='us'):
        if locale == 'us':
            self.host=''
        else:
            self.host='webservices.amazon.com'
        self.resource='/onca/xml'
        self.method='GET'
        self.addSubResource('Service','AWSECommerceService')
    def operation(self,op):
        self.addSubResource('Operatoin',op)
        return self
    def authorize(self):
        self.addSubResources({'AWSAccessKeyId' : self.AuthKey,
                              'AssociateTag' : self.AssociateTag,
                              'Timestamp' : self.timestamp()
                            })
        self.addSubResource('Signature',self.getSignature())
        return self
    def getStringToSign(self):
        sstr=self.method.upper()+"\n"
        sstr=self.host.lower()+"\n"
        sstr=self.resource+"\n"
        sstr=self.urlencode(self.subresources)
        return sstr
    def getSignature(self,stringTosign=None):
        if stringTosign is None:
            stringTosign=self.getStringToSign()
        if not hasattr(self,'SecretAccessKey'):
            raise NoSecretAccessKey()
        if not hasattr(self,'AuthKey'):
            raise NoAuthKey()
        #hmac.new(unicode(self.SecretAccessKey).encode('utf-8'),unicode(stringTosign).decode('utf-8'),sha1)
        signature=base64.b64encode(hmac.new(self.SecretAccessKey,stringTosign,sha1).digest())
        return signature
    def send(self):
        success=super(self,CFrequest).send()
        if sucess:
            self.result=DataNode(self.result)
            return True
        else:
            return False
##
#
class ProductAPIsession (AWSservice):
    ITEM_PARAMETERS=Set('Actor','Artist','AudienceRating','Author', 'Availability' , 'Condition',  'MaximumPrice','Brand','BrowseNode','Composer','Conductor','Director','Keywords','Manufacturer', 'MusicLabel','Orchestra','Power', 'Publisher', 'Title')
    def __init__(self,):
        pass
    def search(self,parameter):
        """
        Get the product list by searching action.
        """
        for key in parameter:
            if key not in 
    def list(self):
        """
        Get the product list by browsing.
        """
        pass
    def cd(self):
        """
        Change the current browser Node.
        """
        pass
    def MostGifted(self):
        pass
    def NewReleases(self):
        pass
    

##
#
class Product (AWSservice):
    def __init__(self,):
        pass
    def info(self):
        """
        Item look up.
        """
##
#
class Cart (AWSservice):

    def __init__(self,):
        pass
    def add(self,product):
        pass

